package com.itheima.web.service.impl.cms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.result.PageResult;
import com.itheima.service.cms.CmsSubjectService;
import com.itheima.utils.StringUtils;
import com.itheima.vo.cms.CmsSubject;
import com.itheima.web.mapper.cms.CmsSubjectMapper;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService
public class CmsSubjectServiceImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject>
                                    implements CmsSubjectService {

    /**
     * 根据专题名称分页获取商品专题
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @Override
    public PageResult listByPage(Integer pageNum, Integer pageSize, String keyword) {
        Page<CmsSubject> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CmsSubject> lqw = new LambdaQueryWrapper<>();
        //模糊查询
        lqw.like(StringUtils.isNotEmpty(keyword),CmsSubject::getCategoryName,keyword);
        this.page(pageInfo,lqw);
        return PageResult.init(pageInfo.getTotal(),pageSize.longValue(),pageNum.longValue(),pageInfo.getRecords());
    }
}
